package com.zhengbing.tj.design.decorator;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

/**
 * 装饰器模式-大写输出装饰器
 *
 * @author zhengbing
 * @date 2025-07-21
 */
public class UppercaseDecorator extends Decorator {
    public UppercaseDecorator(Component component) {
        super(component);
    }

    @Override
    public void operation() {
        // 捕获原有输出并转为大写
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream oldOut = System.out;
        PrintStream newOut = new PrintStream(baos);
        System.setOut(newOut);
        super.operation();
        System.out.flush();
        System.setOut(oldOut);
        String result = baos.toString().toUpperCase();
        System.out.print(result);
    }
} 